﻿using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;


namespace user_defined_Panl
{
    public class Panl_1 : Panel
    {

        public Panl_1(FlowLayoutPanel layoutPanel)
        {
           
            
            FlowLayoutPanel layoutPanel1 = new FlowLayoutPanel();
            layoutPanel1.Size = new  Size(954, 360);
            Panel panel = new Panel();
            panel.Size = new  Size(954, 331);
            TextBox textBox = new TextBox();
            textBox.ScrollBars = ScrollBars.Vertical;
            CheckBox checkBox = new CheckBox();
            checkBox.Font = new Font("楷体", 20);
            checkBox.AutoSize = true;
            checkBox.Text = textBox.Text;
            layoutPanel1.Controls.Add(checkBox);
            textBox.ReadOnly = true;
            textBox.Name = "but0";
            textBox.Multiline = true;
            textBox.Size = new Size(946, 102);
            textBox.Font = new  Font("华文楷体", 20);
            TextBox[] textBoxes = new TextBox[4];

            for (int i = 0; i < 4; i++)
            {

                textBoxes[i] = new TextBox();
                textBoxes[i].ReadOnly = true;
                textBoxes[i].Name = "but" + i + 1;
                textBoxes[i].Multiline = true;
                textBoxes[i].Location = new  Point(62, 114);
                textBoxes[i].Size = new  Size(886, 38);
                textBoxes[i].Font = new  Font("华文楷体", 20);
            }
            textBoxes[0].Location = new  Point(62, 114);
            textBoxes[1].Location = new  Point(62, 170);
            textBoxes[2].Location = new  Point(62, 226);
            textBoxes[3].Location = new  Point(62, 282);
            panel.Controls.Add(textBox);
            panel.Controls.AddRange(textBoxes);
            checkBox.BackColor = Color.Transparent;

            RadioButton[] radios = new RadioButton[4];
            for (int i = 0; i < 4; i++)
            {
                radios[i] = new RadioButton();
                radios[i].Font = new  Font("华文楷体", 20);
                radios[i].AutoSize = true;
                radios[i].Enabled = false;
            }
            radios[0].Text = "A";
            radios[0].Location = new  Point(10, 118);
            radios[1].Text = "B";
            radios[1].Location = new  Point(11, 174);
            radios[2].Text = "C";
            radios[2].Location = new  Point(11, 230);
            radios[3].Text = "D";
            radios[3].Location = new  Point(11, 286);
            panel.Controls.AddRange(radios);

            layoutPanel1.Controls.Add(panel);
            layoutPanel.Controls.Add(layoutPanel1);

        }
    }
    public class Panl_2 : Panel
    {
        public Panl_2(FlowLayoutPanel layoutPanel)
        {
            FlowLayoutPanel layoutPanel1 = new FlowLayoutPanel();
            layoutPanel1.Size = new  Size(954, 360);
            Panel panel = new Panel();
            panel.Size = new  Size(954, 331);
            TextBox textBox = new TextBox();
            CheckBox checkBox = new CheckBox();
            checkBox.Font = new Font("楷体", 20);
            checkBox.AutoSize = true;
            checkBox.Text = textBox.Text;
            layoutPanel1.Controls.Add(checkBox);

            textBox.Name = "but0";
            textBox.ReadOnly = true;
            textBox.Multiline = true;
            textBox.Size = new  Size(946, 102);
            textBox.Font = new  Font("华文楷体", 20);
            TextBox[] textBoxes = new TextBox[4];

            for (int i = 0; i < 4; i++)
            {
                textBoxes[i] = new TextBox();
                textBoxes[i].ReadOnly = true;
                textBoxes[i].Name = "but" + i + 1;
                textBoxes[i].Multiline = true;
                textBoxes[i].Location = new  Point(62, 114);
                textBoxes[i].Size = new  Size(886, 38);
                textBoxes[i].Font = new  Font("华文楷体", 20);
            }
            textBoxes[0].Location = new  Point(62, 114);
            textBoxes[1].Location = new  Point(62, 170);
            textBoxes[2].Location = new  Point(62, 226);
            textBoxes[3].Location = new  Point(62, 282);
            panel.Controls.Add(textBox);
            panel.Controls.AddRange(textBoxes);
            checkBox.BackColor = Color.Transparent;

            CheckBox[] radios = new CheckBox[4];
            for (int i = 0; i < 4; i++)
            {
                radios[i] = new CheckBox();
                radios[i].Font = new  Font("华文楷体", 20);
                radios[i].AutoSize = true;
                radios[i].Enabled = false;
            }
            radios[0].Text = "A";
            radios[0].Location = new  Point(10, 118);
            radios[1].Text = "B";
            radios[1].Location = new  Point(11, 174);
            radios[2].Text = "C";
            radios[2].Location = new  Point(11, 230);
            radios[3].Text = "D";
            radios[3].Location = new  Point(11, 286);
            panel.Controls.AddRange(radios);

            layoutPanel1.Controls.Add(panel);
            layoutPanel.Controls.Add(layoutPanel1);

        }
    }
    public class Panl_3 : Panel
    {
        public Panl_3(FlowLayoutPanel layoutPanel)
        {
            FlowLayoutPanel layoutPanel1 = new FlowLayoutPanel();
            layoutPanel1.Size = new  Size(954, 250);
            Panel panel = new Panel();
            panel.Size = new  Size(954, 250);
            TextBox textBox = new TextBox();
            CheckBox checkBox = new CheckBox();
            checkBox.Font = new Font("楷体", 20);
            checkBox.AutoSize = true;
            checkBox.Text = textBox.Text;
            layoutPanel1.Controls.Add(checkBox);

            textBox.Name = "but0";
            textBox.ReadOnly = true;
            textBox.Multiline = true;
            textBox.Size = new  Size(946, 102);
            textBox.Font = new  Font("华文楷体", 20);

            panel.Controls.Add(textBox);
            checkBox.BackColor = Color.Transparent;

            RadioButton[] radios = new RadioButton[2];
            for (int i = 0; i < 2; i++)
            {
                radios[i] = new RadioButton();
                radios[i].Font = new  Font("华文楷体", 20);
                radios[i].AutoSize = true;
                radios[i].Enabled = false;
            }
            radios[0].Text = "true";
            radios[0].Location = new  Point(10, 118);
            radios[1].Text = "false";
            radios[1].Location = new  Point(11, 174);

            panel.Controls.AddRange(radios);

            layoutPanel1.Controls.Add(panel);
            layoutPanel.Controls.Add(layoutPanel1);

        }
    }
    public class Panl_4 : Panel
    {
        public Panl_4(FlowLayoutPanel layoutPanel)
        {
            FlowLayoutPanel layoutPanel1 = new FlowLayoutPanel();
            layoutPanel1.Size = new  Size(954, 360);
            FlowLayoutPanel panel = new FlowLayoutPanel();
            panel.Size = new  Size(954, 360);
            TextBox textBox = new TextBox();
            CheckBox checkBox = new CheckBox();
            checkBox.Font = new Font("楷体", 20);
            checkBox.AutoSize = true;
            checkBox.Text = textBox.Text;
            layoutPanel1.Controls.Add(checkBox);

            textBox.Name = "but0";
            textBox.ReadOnly = true;
            textBox.Multiline = true;
            textBox.Size = new  Size(946, 102);
            textBox.Font = new  Font("华文楷体", 20);
            TextBox textBox2 = new TextBox();
            textBox2.Name = "but1";
            textBox2.ReadOnly = true;
            textBox2.Multiline = true;
            textBox2.Size = new  Size(946, 102);
            textBox2.Font = new  Font("华文楷体", 20);

            panel.Controls.Add(textBox);
            panel.Controls.Add(textBox2);

            layoutPanel1.Controls.Add(panel);
            layoutPanel.Controls.Add(layoutPanel1);
        }
    }
    public class FlowLayoutPanel_2 : FlowLayoutPanel
    {
        public FlowLayoutPanel_2( MultipleChoice multiple,string tag,bool y=true,bool ischeckBox=true)
        {
            //存入答案
            this.Tag =multiple.Answer+"|"+ multiple.Score;
            //标识
            this.AutoSize = true;
            FlowLayoutPanel panel = new FlowLayoutPanel();
            panel.AutoSize = true;
            CheckBox checkBox = new CheckBox();
            checkBox.Font = new Font("华文楷体", 20);
            checkBox.AutoSize = true;
            checkBox.Tag = multiple.MCID;
            checkBox.Text = tag+$".({multiple.Score}分)";
            this.Controls.Add(checkBox);
            #region 生成题干
            UILabel textBox = new UILabel();
            textBox.AutoSize = true;
            textBox.MinimumSize = new Size(800,0); 
            textBox.MaximumSize = new Size(800,0);
            textBox.Size = new Size(800,0);
            textBox.Text = multiple.Topic;
            textBox.Margin = new Padding(0, 0, 0, 10);
            textBox.Font = new Font("华文楷体", 25);
            panel.Controls.Add(textBox);
            UILabel[] textBoxes = new UILabel[4];
            //判断是单选还是多选
            if (ischeckBox)
            {
                CheckBox[] radios = new CheckBox[4];
                for (int i = 0; i < 4; i++)
                {
                    textBoxes[i] = new UILabel();
                    textBoxes[i].AutoSize = true;
                    textBoxes[i].MinimumSize = new Size(750, 25);
                    textBoxes[i].MaximumSize = new Size(750, 0);
                    textBoxes[i].Font = new Font("华文楷体", 23);
                    textBoxes[i].BorderStyle = BorderStyle.None;
                    radios[i] = new CheckBox();
                    radios[i].Font = new Font("华文楷体", 20);
                    radios[i].AutoSize = true;
                    if (y)
                    {
                        radios[i].Enabled = false;
                    }
                    panel.Controls.Add(radios[i]);
                    panel.Controls.Add(textBoxes[i]);
                }
               
                radios[0].Text = "A";
                radios[1].Text = "B";
                radios[2].Text = "C";
                radios[3].Text = "D";
               
            }
            else
            {
               RadioButton[] radios = new RadioButton[4];
                for (int i = 0; i < 4; i++)
                {
                    textBoxes[i] = new UILabel();
                    textBoxes[i].AutoSize = true;
                    textBoxes[i].MinimumSize = new Size(750, 25);
                    textBoxes[i].MaximumSize = new Size(750, 0);
                    textBoxes[i].Font = new Font("华文楷体", 23);
                    textBoxes[i].BorderStyle = BorderStyle.None;
                    radios[i] = new RadioButton();
                    radios[i].Font = new Font("华文楷体", 20);
                    radios[i].AutoSize = true;
                    if (y)
                    {
                        radios[i].Enabled = false;
                    }
                    panel.Controls.Add(radios[i]);
                    panel.Controls.Add(textBoxes[i]);
                  
                }
                radios[0].Text = "A";
                radios[1].Text = "B";
                radios[2].Text = "C";
                radios[3].Text = "D";
            }
           
            #endregion 写入题
            textBoxes[0].Text = multiple.A;
            textBoxes[1].Text = multiple.B;
            textBoxes[2].Text = multiple.C;
            textBoxes[3].Text = multiple.D;
            //是否写入答案
            if (y)
            {
                int a = 0;
                for (int i = 0; i < panel.Controls.Count; i++)
                {
                    if (ischeckBox)
                    {
                        if (panel.Controls[i] is CheckBox)
                        {
                            if (panel.Controls[i] .Text == multiple.Answer[a].ToString())
                            {
                                (panel.Controls[i] as CheckBox).Checked = true;
                                a++;
                            } 
                        }
                    }
                    else
                    {
                        if (panel.Controls[i] is RadioButton)
                        {
                            if (panel.Controls[i].Text == multiple.Answer.ToString())
                            {
                                (panel.Controls[i] as RadioButton).Checked = true;
                                break;
                            }
                        }
                    }
                }
            }
            this.Controls.Add(panel);
        }
    }
    public class FlowLayoutPanel_3 : FlowLayoutPanel
    {
        public FlowLayoutPanel_3(TrueOrFalseQuestions completion, string tag, bool y = true)
        {
            //答案
            this.Tag = completion.Answer + "|" + completion.Score;
            this.AutoSize =true;
            FlowLayoutPanel panel = new FlowLayoutPanel();
            panel.AutoSize = true;

            //标识
            CheckBox checkBox = new CheckBox();
            checkBox.Tag = completion.SPID;
            checkBox.Font = new Font("华文楷体", 20);
            checkBox.AutoSize = true;
            checkBox.Text = $"{tag}.({completion.Score}分)";
            //题目
            UILabel textBox = new UILabel();
            textBox.AutoSize=true;
            textBox.MinimumSize = new Size(800,0);
            textBox.MaximumSize = new Size(800,0);
            textBox.Font = new Font("华文楷体", 23);
            textBox.Text = completion.Topic;
            textBox.Margin = new Padding(0, 0, 0, 10);
            panel.Controls.Add(textBox);
            //答题区
            RadioButton[] radios = new RadioButton[2];
            if (y)
            {
                for (int i = 0; i < 2; i++)
                {
                    radios[i] = new RadioButton();
                    radios[i].Font = new Font("华文楷体", 20);
                    radios[i].AutoSize = true;
                    radios[i].Enabled = false;
                }
            }
            else
            {
                for (int i = 0; i < 2; i++)
                {
                    radios[i] = new RadioButton();
                    radios[i].Font = new Font("华文楷体", 20);
                    radios[i].AutoSize = true;
                    radios[i].Enabled = true;
                }
            }
            radios[0].Text = "true";
            radios[0].Location = new Point(10, 118);
            radios[1].Text = "false";
            radios[1].Location = new Point(11, 174);
            //是否显示答案
            if (y)
            {
                radios[0].Checked = completion.Answer == radios[0].Text ? true : false;
                radios[1].Checked = completion.Answer == radios[1].Text ? true : false;
            }
            panel.Controls.AddRange(radios);
            this.Controls.Add(checkBox);
            this.Controls.Add(panel);
        }
    }
    public class FlowLayoutPanel_4 : FlowLayoutPanel
    {
        public FlowLayoutPanel_4(Completion completion,string tag,bool y=true)
        {
            
            //答案
            this.Tag= completion.Answer+"|"+completion.Score+"|"+completion.ScoringPoint;
            this.AutoSize = true;
            this.MinimumSize = new Size(800,0);
            this.MaximumSize = new Size(800,0);
            FlowLayoutPanel panel = new FlowLayoutPanel();
            FlowLayoutPanel pane2 = new FlowLayoutPanel();
            panel.AutoSize = true;
            panel.MinimumSize = new Size(800,0);
            panel.MaximumSize = new Size(800, 0);
            pane2.AutoSize = true;
            pane2.MinimumSize = new Size(800, 0);
            pane2.MaximumSize = new Size(800, 0);

            //标识
            CheckBox checkBox = new CheckBox();
            checkBox.Tag = completion.CPID;
            checkBox.Font = new Font("华文楷体", 20);
            checkBox.AutoSize = true;
            checkBox.Text = $"{tag}.({completion.Score}分)";
            
            //题目
            UILabel textBox = new UILabel();
            textBox.Name = "but0";
            textBox.AutoSize = true;
            textBox.MinimumSize = new Size(800,0);
            textBox.MaximumSize = new Size(800, 0);
            textBox.Font = new Font("华文楷体", 23);
            textBox.Text = completion.Topic;
            textBox.Margin = new Padding(0,0,0,10);
            //答题区
            if (y)
            {
                UILabel uILabel = new UILabel();
                uILabel.Text = completion.Answer;
                uILabel.AutoSize = true;
                uILabel.Font = new Font("华文楷体", 23);
                uILabel.MinimumSize = new Size(800,0);
                uILabel.MaximumSize = new Size(800,0);
                pane2.Controls.Add(uILabel);
            }
            else
            {
                TextBox textBox2 = new TextBox();
                textBox2.Name = "but1";
                textBox2.Multiline = true;
                textBox2.Font = new Font("华文楷体", 23);
                textBox2.Size = new Size(800,100);
                textBox2.ScrollBars = ScrollBars.Both;
                textBox2.ReadOnly = false;
                textBox2.BackColor=SystemColors.ActiveCaption;
                textBox2.BorderStyle = BorderStyle.None;
                pane2.Controls.Add(textBox2);
            }
            panel.Controls.Add(textBox);
            this.Controls.Add(checkBox);
            this.Controls.Add(panel);
            this.Controls.Add(pane2);
        }
    }
}
